package com.ruoyi.receipt.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.receipt.domain.TbKnowledgePlan;
import com.ruoyi.receipt.service.ITbKnowledgePlanService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.IdWorker;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 知识点教案Controller
 * 
 * @author ruoyi
 * @date 2021-03-31
 */
@RestController
@RequestMapping("/receipt/knowledgePlan")
public class TbKnowledgePlanController extends BaseController
{
    @Autowired
    private ITbKnowledgePlanService tbKnowledgePlanService;

    @Autowired
    private IdWorker idWorker;

    /**
     * 查询知识点教案列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbKnowledgePlan tbKnowledgePlan)
    {
        startPage();
        List<TbKnowledgePlan> list = tbKnowledgePlanService.selectTbKnowledgePlanList(tbKnowledgePlan);
        return getDataTable(list);
    }

    /**
     * 导出知识点教案列表
     */
    @Log(title = "知识点教案", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbKnowledgePlan tbKnowledgePlan)
    {
        List<TbKnowledgePlan> list = tbKnowledgePlanService.selectTbKnowledgePlanList(tbKnowledgePlan);
        ExcelUtil<TbKnowledgePlan> util = new ExcelUtil<TbKnowledgePlan>(TbKnowledgePlan.class);
        return util.exportExcel(list, "plan");
    }

    /**
     * 获取知识点教案详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbKnowledgePlanService.selectTbKnowledgePlanById(id));
    }

    /**
     * 根据知识点编号查询知识点教案
     * @param id 知识点编号
     * @return
     */
    @GetMapping(value = "/getPlanByManagerId/{id}")
    public AjaxResult getPlanByManagerId(@PathVariable("id") Long id)
    {
        TbKnowledgePlan planByManager = tbKnowledgePlanService.getPlanByManagerId(id);
        return AjaxResult.success(planByManager);
    }

    /**
     * 新增知识点教案
     */
    @Log(title = "知识点教案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbKnowledgePlan tbKnowledgePlan)
    {
        tbKnowledgePlan.setId(idWorker.nextId());
        return toAjax(tbKnowledgePlanService.insertTbKnowledgePlan(tbKnowledgePlan));
    }

    /**
     * 修改知识点教案
     */
    @Log(title = "知识点教案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbKnowledgePlan tbKnowledgePlan)
    {
        return toAjax(tbKnowledgePlanService.updateTbKnowledgePlan(tbKnowledgePlan));
    }
    /**
     * 删除知识点教案
     */
    @Log(title = "知识点教案", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbKnowledgePlanService.deleteTbKnowledgePlanByIds(ids));
    }
}
